<template>
  <div id="material_center" :style="{ '--color': `${theme_color}` }">
    <c-title :hide="false" :text="'素材中心'"></c-title>
    <div class="tabs-wrap">
      <div class="wrap">
        <van-tabs v-model="active" @click="onClick" :color="theme_color" :title-active-color="theme_color" style="overflow-x: scroll;" class="noticeellipsis">
          <van-tab name="0" title="全部" style="overflow: visible; white-space: nowrap; text-overflow: clip;"> </van-tab>
          <van-tab v-for="(item, index) in catgoryList" :key="index" :name="item.id" :title="item.name" style="overflow: visible; white-space: nowrap; text-overflow: clip;"> </van-tab>
        </van-tabs>
        <div class="sousuo"><i class="iconfont icon-sousuo1" @click="toSousuo"></i></div>
      </div>
      <div class="second-block" v-if="second_catgory.length > 0 && status">
        <div style="width: 80%;" class="block-wrap">
          <div class="block" :class="[childid == item.id ? 'activeColor' : '']" v-for="(item, index) in second_catgory" :key="index" @click="changeSecond(item.id)">
            {{ item.name }}
          </div>
        </div>
        <div class="slideUp" @click.stop="close">
          收起
          <i class="iconfont icon-member-left"></i>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="user_info" v-for="(item, i) in list" :key="i">
        <div class="user_name">
          <div class="user">
            <img :src="item.logo" />
          </div>
          <ul class="right">
            <li class="name">{{ item.name }}</li>
            <li class="time">{{ item.created_at }}</li>
          </ul>
          <div class="copy" @click="update(item.id)" v-clipboard:copy="item.content" v-clipboard:success="onCopy" v-clipboard:error="onError">
            <i class="iconfont icon-fuzhi"></i>
            复制
          </div>
        </div>
        <h3>{{item.title}}</h3>
        <p class="share_text" v-html="item.content1">
          <!-- {{ item.content }} -->
        </p>
        <viewer :images="item.images" class="goods_box">
          <div class="img" v-for="(img, i) in item.images" :key="i">
            <img :src="img" />
          </div>
          <div class="video" v-if="item.videos && item.videos.video_url">
            <video
              :id="'video' + i"
              :src="item.videos.video_url"
              :poster="item.videos.video_image"
              style="width: 100%; height: 100%;"
              @play="onPlayerPlay(i)"
              x5-video-player-type="h5"
              controls
              x5-video-player-fullscreen="true"
            ></video>
          </div>
        </viewer>

        <div class="goods_lik" v-if="item.goods && item.goods_id !== 0" @click="toGoods(item.goods.id)">
          <div class="goods_img">
            <img :src="item.goods.thumb" />
          </div>
          <ul class="goods_name">
            <li class="name" style="-webkit-box-orient: vertical;">
              {{ item.goods.title | escapeTitle }}
            </li>
            <li class="number">{{ $i18n.t("money") }}{{ item.goods.price }}</li>
          </ul>
        </div>
        <div class="goods_share">
          <div class="right" @click.stop="downImage(item.images)" v-if="fun.isCPS()">
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FmaterialCenter%2F%E7%BB%84%20565%402x.png" alt="" />
            <span>下载图片</span>
          </div>
          <div class="left" @click.stop="postShow(item.goods.id)">
            <i class="iconfont icon-material_goodsCode"></i>
            <span>商品码</span>
          </div>
          <div class="right" @click="toDetail(item.id)">
            <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FmaterialCenter%2Fsc%402x%20(1).png" alt="" />
            <span>素材详情</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 分享
    <van-popup v-model="show1" position="bottom" :style="{height:'330px'}" @click.stop>
      <div class="share_popup_box">
        <div class="tips">提示</div>
        <ul class="text">
          <li>
            <i class="iconfont icon-info-complete current"></i>
            <span>文案已复制</span>
          </li>
          <li>
            <i class="iconfont icon-info-complete"></i>
            <span>长按素材图片保存至相册</span>
          </li>
          <li>
            <i class="iconfont icon-info-complete"></i>
            <span>点击<em>商品码</em>长按保存至相册</span>
          </li>
        </ul>
        <div class="title">
          <div class="line_left"></div>
          <span>分享</span>
          <div class="line_right"></div>
        </div>
        <div class="share_list">
          <div class="list">
            <div class="img">
              <img src="../../assets/images/material_share_a.png" />
            </div>
            <span>打开微信</span>
          </div>
          <div class="list">
            <div class="img">
              <img src="../../assets/images/material_share_c.png" />
            </div>
            <span>粘贴文案/上传图片</span>
          </div>
          <div class="list">
            <div class="img">
              <img src="../../assets/images/material_share_d.png" />
            </div>
            <span>发布朋友圈</span>
          </div>
        </div>
        <div class="block"></div>
        <div class="share_btn" @click="show1 = false">
          <button type="button">取消</button>
        </div>
      </div>
    </van-popup> -->
    <!-- 商品码 -->
    <van-popup v-model="posterShow" position="center" round :style="{ width: '320px', background: 'transparent', overflow: 'inherit' }" @click.stop>
      <div class="goods_code_popup">
        <img :src="'data:' + posterImg.mime + ';base64,' + posterImg.base64Image" v-if="posterImg.base64Image" style="width: 100%; border-radius: 0.375rem;" />
        <img src="../../assets/images/img_default.png" v-if="!posterImg.base64Image" style="width: 100%; height: 100%; border-radius: 0.375rem;" />
        <div class="close" @click="posterShow = false">
          <img src="../../assets/images/material_close.png" />
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import material_center_controller from "./material_center_controller";

export default material_center_controller;
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
#material_center {
  .wrap {
    position: relative;
    display: flex;
    background: #fff;

    .noticeellipsis {
      overflow: visible;
      white-space: nowrap;
      text-overflow: clip;
      flex-basis: auto !important;
    }

    .sousuo {
      background-color: #fff;
      position: absolute;
      right: 1rem;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      z-index: 99;
    }

    .van-tabs {
      margin-right: 2.81rem;

      ::v-deep .van-tab {
        padding: 0 0.625rem;
      }
    }
  }

  .wrap::after {
    content: "";
    position: absolute;
    right: 2.81rem;
    top: 10%;
    height: 80%;
    width: 0.13rem;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.45) 0%, rgba(84, 84, 84, 0.3) 100%);
  }

  .tabs-wrap {
    position: relative;
    // z-index: 99;

    .second-block {
      min-height: 3.125rem;
      background-color: #f6f6f6;
      // position: absolute;
      width: 100%;
      z-index: 99;
      box-sizing: border-box;
      padding: 0.75rem;
      box-sizing: border-box;
      display: flex;
      // box-shadow: 0.3125rem 0.3125rem 0.1563rem #ccc;
      justify-content: space-between;
      align-items: center;

      .block-wrap {
        display: flex;
        overflow-x: scroll;

        .block {
          padding: 0.25rem 0.5rem;
          box-sizing: border-box;
          background-color: #fff;
          color: var(--color);
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 1.38rem;
          flex-shrink: 0;
          font-size: 0.75rem;
          border-radius: 0.78rem;
        }

        &::-webkit-scrollbar {
          display: none; /* Chrome Safari */
        }
      }

      .slideUp {
        // position: absolute;
        // right: 0.9375rem;
        // bottom: 0.3125rem;
        font-size: 0.75rem;

        .icon-member-left {
          margin-left: 0.1563rem;
          transform: rotate(90deg);
          display: inline-block;
          font-size: 0.5rem;
        }

        // .icon-member-left::before {
        //   width: 0.54rem;
        //   height: 0.54rem;
        // }
      }
    }
  }

  .content {
    padding-bottom: 3rem;
    padding-top: 0.5rem;

    .user_info {
      margin: 0 0.75rem;
      margin-bottom: 0.75rem;
      padding: 0 0.63rem;
      box-sizing: border-box;
      // padding: 0 0.9375rem;
      background: #fff;
      // border-top: solid 0.0625rem #ebebeb;
      // border-bottom: solid 0.0625rem #ebebeb;
      margin-bottom: 0.625rem;
      border-radius: 0.5rem;
      h3 {
        text-align: left;
        font-weight: bold;
        font-size: 1rem;
        color: #161616;
        padding:0.9375rem 0 0 0;
      }
      .user_name {
        display: flex;
        padding-top: 0.9375rem;

        .user {
          width: 2.25rem;
          height: 2.25rem;
          border-radius: 100%;
          border: solid 0.0625rem #ebebeb;
          overflow: hidden;
          background: #f2f2f2;
          margin-right: 0.5rem;

          img {
            width: 100%;
            height: 100%;
          }
        }

        .right {
          flex: 1;
          text-align: left;
          font-size: 0.94rem;

          .name {
            // margin-bottom: 0.5rem;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-weight: bold;
            line-height: 1.31rem;
          }

          .time {
            font-size: 0.75rem;
            color: #999;
            line-height: 1.03rem;
          }
        }

        .copy {
          display: flex;
          align-items: center;
          margin-right: 0.5rem;
          font-size: 0.88rem;
          color: var(--color);

          .iconfont {
            margin-right: 0.13rem;
          }
        }
      }

      .share_text {
        font-size: 0.94rem;
        line-height: 1.5rem;
        text-align: left;
        margin-top: 0.625rem;
        margin-bottom: 0.75rem;
      }

      .goods_box {
        display: flex;
        flex-wrap: wrap;
        max-height: 21.875rem;
        overflow: hidden;

        .video {
          width: 6.9375rem;
          height: 6.9375rem;
          overflow: hidden;
          margin-bottom: 0.375rem;
          position: relative;
        }

        .img {
          width: 6.64rem;
          height: 7.34rem;
          overflow: hidden;
          border-radius: 0.25rem;
          // background: #f2f2f2;
          margin-right: 0.28rem;
          margin-bottom: 0.375rem;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }

        .img:nth-child(3n) {
          margin: 0;
        }
      }

      .goods_lik {
        background: #f7f7f7;
        margin-top: 0.25rem;
        display: flex;
        padding: 0.5rem;
        box-sizing: border-box;
        border-radius: 0.625rem;

        .goods_img {
          flex-shrink: 0;
          width: 5rem;
          height: 4.06rem;
          overflow: hidden;
          border-radius: 0.13rem;
          margin-right: 0.5rem;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }

        .goods_name {
          flex: 1;
          text-align: left;
          overflow: hidden;
          display: flex;
          flex-direction: column;
          justify-content: center;

          .name {
            font-size: 0.81rem;
            color: #333;
            text-overflow: ellipsis;
            overflow: hidden;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }

          .number {
            font-size: 0.94rem;
            color: #f84949;
            margin-top: 0.5rem;
          }
        }
      }

      .goods_share {
        margin-top: 0.625rem;
        // border-top: solid 0.0625rem #ebebeb;
        display: flex;
        align-items: center;
        padding: 0.625rem 0;

        .left,
        .right {
          display: flex;
          width: 50%;
          // border-right: solid 0.0625rem #ebebeb;
          font-size: 0.81rem;
          color: #999;
          justify-content: center;
          align-items: center;

          .iconfont {
            margin-right: 0.375rem;
            color: #999;
            font-size: 1.125rem;
          }
        }

        .right img {
          width: 1rem;
          height: 1rem;
          margin: 0;
          margin-right: 0.13rem;
        }

        .right {
          border: none;
        }
      }
    }
  }

  .share_popup_box {
    background: #fff;

    .tips {
      font-size: 16px;
      font-weight: bold;
      margin-top: 1rem;
    }

    .text {
      padding: 1.5rem 0.9375rem;
      display: flex;
      flex-wrap: wrap;

      li {
        width: 100%;
        font-size: 14px;
        text-align: left;
        display: flex;
        padding: 0.375rem 0;

        .iconfont {
          font-size: 1.125rem;
          margin-right: 0.25rem;
          color: #999;
        }

        .current {
          color: #07be12;
        }

        em {
          text-decoration: underline;
          color: #4c7fff;
        }
      }
    }

    .title {
      padding: 0 0.9375rem;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .line_left,
      .line_right {
        width: 7.5rem;
        height: 0.0625rem;
        background: #ebebeb;
      }

      span {
        font-size: 20px;
      }
    }

    .share_list {
      padding: 1.25rem 0.9375rem;
      display: flex;
      justify-content: space-around;

      .list {
        display: flex;
        align-items: center;
        margin: 0 0.2rem;

        .img {
          width: 1.2rem;
          height: 1.2rem;
          overflow: hidden;
          margin-right: 0.1rem;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

    .block {
      height: 0.625rem;
      background: #f5f5f5;
    }

    .share_btn {
      button {
        border: none;
        height: 3.125rem;
        font-size: 16px;
      }
    }
  }

  .goods_code_popup {
    background: #fff;
    border-radius: 0.5rem;
    position: relative;
    width: 90%;
    display: inline-block;
    margin: 0 auto;

    .goods_img {
      width: 20rem;
      height: 20rem;
      background: #f2f2f2;
      overflow: hidden;
      padding: 0.25rem;
      border-radius: 0.375rem 0.375rem 0 0;

      img {
        width: 85%;
      }
    }

    .goods_info {
      display: flex;
      justify-content: space-between;
      padding: 0.625rem;

      .info_left {
        width: 12.5rem;

        .name {
          font-size: 14px;
          line-height: 1.25rem;
          height: 2.5rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }

        .price {
          font-size: 24px;
          color: #f15353;
          text-align: left;
          margin-top: 0.75rem;
          font-weight: bold;

          span {
            font-size: 14px;
            color: #8c8c8c;
            text-decoration: line-through;
            margin-left: 0.9375rem;
            font-weight: normal;
          }

          font {
            font-size: 14px;
          }
        }
      }

      .info_right {
        .code_img {
          width: 5.5rem;
          height: 5.5rem;
          background: #f2f2f2;
          overflow: hidden;

          img {
            width: 100%;
          }
        }

        span {
          font-size: 12px;
          line-height: 1.25rem;
        }
      }
    }

    .close {
      position: absolute;
      top: -1rem;
      right: -1rem;
      width: 2.75rem;
      height: 2.75rem;
      overflow: hidden;

      img {
        width: 80%;
      }
    }
  }

  .activeColor {
    color: #fff !important;
    background-color: var(--color) !important;
  }
}
</style>
